local dengxian = fk.CreateSkill{
  name = "xiaobai__dengxian",
  tags = {Skill.Wake}
}

Fk:loadTranslationTable{
  ["xiaobai__dengxian"] = "登仙",
  [":xiaobai__dengxian"] = "觉醒技，“三法”及“释道”所有句段均执行后，你将体力上限调整为9，"..
    "然后可令一名其他角色获得“三法”。此后你的“三法”可以进行逆向转换。",

  ["#xiaobai__dengxian"] = "登仙：你可以令一名其他角色获得“三法”",

  ["$xiaobai__dengxian1"] = "授汝五雷诸法，莫忘垂济世人",
  ["$xiaobai__dengxian2"] = "感汝诚善，吾亲赐汝除难之法",
}

local dengxian_spec =  {
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(self) 
      and player:usedSkillTimes(dengxian.name, Player.HistoryGame) == 0 
      and (event ~= fk.DamageFinished or (data.damageType and data.damageType ~= fk.NormalDamage))
  end,
  can_wake = function (self, event, target, player, data)
    return #player:getMark("xiaobai__sanfa_previous") > 1 and #player:getMark("xiaobai__sanfa_next") > 1  and
           player:getMark("xiaobai__shidao_previous") > 0 and player:getMark("xiaobai__shidao_next") > 0
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:changeMaxHp(player, 9 - player.maxHp)
    if player.dead then return end

    local t = room:askToChoosePlayers(player, {
      min_num = 1,
      max_num = 1,
      targets = table.filter(room:getOtherPlayers(player), function (p)
        return not p:hasSkill(dengxian.name, true, true)
      end),
      skill_name = dengxian.name,
      prompt = "#xiaobai__dengxian"
    })
    if #t > 0 then
      room:handleAddLoseSkills(t[1], "xiaobai__sanfa")
    end
  end
}

dengxian:addEffect(fk.CardUseFinished, dengxian_spec)
dengxian:addEffect(fk.DamageFinished, dengxian_spec)

return dengxian